#include "stdafx.h"
//-------------------------------------------------------------------------------------------------
//ImageProp.cpp  - a property for a particular Image - abstract class
//	typically an Image has one or more properties that a user can edit in the Property Window (top part)           
//-------------------------------------------------------------------------------------------------
//FreeBSD License
//Copyright 2011 Will Stott All rights reserved.
//
//Redistribution and use in source and binary forms, with or without modification, are
//permitted provided that the following conditions are met:
//
//   1. Redistributions of source code must retain the above copyright notice, this list of
//      conditions and the following disclaimer.
//
//   2. Redistributions in binary form must reproduce the above copyright notice, this list
//      of conditions and the following disclaimer in the documentation and/or other materials
//      provided with the distribution.
//
//THIS SOFTWARE IS PROVIDED BY Will Stott ``AS IS'' AND ANY EXPRESS OR IMPLIED
//WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
//FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL Will Stott OR
//CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
//CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
//SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
//ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
//NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
//ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
//
//The views and conclusions contained in the software and documentation are those of the
//authors and should not be interpreted as representing official policies, either expressed
//or implied, of Will Stott.
//
//----Authors--------------------------------------------------------------------------------------
//created by: will.stott@ucl.ac.uk Sept 2011
//
//----Comments-------------------------------------------------------------------------------------
//
// The following ifdef block is the standard way of creating macros which make exporting 
// from a DLL simpler. All files within this DLL are compiled with the IMAGEPROCLIB_EXPORTS
// symbol defined on the command line. this symbol should not be defined on any project
// that uses this DLL. This way any other project whose source files include this file see 
// IMAGEPROCLIBAPI functions as being imported from a DLL, whereas this DLL sees symbols
// defined with this macro as being exported.
//--------------------------------------------------------------------------------------------------

#include <assert.h>
#include "ImageDataset.h"
#include "ImageProp.h"

#include "ImagePropInteger.h"
#include "ImagePropTextLine.h"
#include "ImagePropTextLines.h"

const char * const ImageProp::xmlCtrlSpin = "Spin";
const char * const ImageProp::xmlCtrlSLEdit = "CEdit";
const char * const ImageProp::xmlCtrlMLEdit = "Textbox";

	//<Header>
	//   <ImageTypes>Types of Images found in Static Image Review
    //        <ImageType>Ovary TS</ImageType>
	//				<ImageTypeProps>Properties for this type of image
	//					<ImageTypeProp Type="ImagePropTextLines" Control="CEdit" ValMin="-1" ValMax="500" Prompt="Enter text to describe image">Notes</ImageTypeProp>
	//					<ImageTypeProp Type="ImagePropInteger" Control="Spin" ValMin="1" ValMax="3" Prompt="Enter quality score image">Quality</ImageTypeProp>
	//				</ImageTypeProps>
	//				<ImageTypeImageObjects>Types of Objects found in this type of image
    //					<ImageTypeImageObject Base="PtShape" PtCode="INC" PenColour="0:0:0" ExpertMaxObjs="-1" MenuName="Inc Cyst">Inclusion Cyst
    //                    <ImageTypeProps>Properties of an Inclusion Cyst Image Object
    //                        <ImageTypeProp Type="ImagePropTextLines" Control="CEdit" ValMin="-1" ValMax="500" Prompt="Enter text to describe Inclusion Cyst">Notes</ImageTypeProp>
	//					      <ImageTypeProp Type="ImagePropInteger" Control="Spin" ValMin="1" ValMax="3" Prompt="Enter quality score for Inclusion Cyst">Quality</ImageTypeProp>
	//					  </ImageTypeProps>
	//					</ImageTypeImageObject>
	//					... other ImageTypeImageObjects go here
	//				<ImageTypeImageObjects>
	//	 </ImageTypes>		
	//   ...
	//<Header>
	//<Body>
	//   <Images>
	//		<Image ImageType="Ovary TS" Notes="this is a nice clear image" Quality="1" >1.2.826.999999.1.9999.1.20080115012154575.1.3.0 
	//			<ImageObject Type="Inclusion Cyst" Note="this is a poor example" Quality="3" PtCnt="76" y1="176" x1="346" ... y76="176" x76="346">1316593822</ImageObject>
	//			<ImageObject Type="Inclusion Cyst" Note="this is a better example" Quality="2" PtCnt="65" y1="21" x1="234"... y65="21" x65="234" >1316593823</ImageObject>
	//		</Image>
	//		...
	//	 </Images>
	//</Body>
	//
	//...........................................................................................................
	//   Owner <ImageType>
	//		<ImageTypeProp Type="ImagePropInteger" Control="Spin" ValMin="1" ValMax="3" Prompt="Enter quality score image">Quality</ImageTypeProp>
	//   Owner <ImageTypeImageObject>
	//		<ImageTypeProp Type="ImagePropTextLines" Control="CEdit" ValMin="-1" ValMax="500" Prompt="Enter text to describe Inclusion Cyst">Notes</ImageTypeProp>
	//...........................................................................................................

ImageProp::ImageProp(void) : 
	_pOwnerType('\0')
{
}


ImageProp::~ImageProp(void)
{
}

ImageProp *ImageProp::CreateImageProp(const char *xmlPropName, const char *xmlValue, ImageTypeProp *pOwnerType)
{
	ImageProp *rc = '\0';

	if ( (xmlPropName != '\0') && (xmlValue != '\0') && (pOwnerType != '\0'))
	{
		std::string attribName = xmlPropName;
		std::string make = pOwnerType->GetType();


		if (make == ImagePropInteger::className)
		{
			rc =  new ImagePropInteger(ImageDataset::MakeWellFormedAttributeName(attribName), std::atoi(xmlValue));
			rc->SetOwnerType(pOwnerType);
		}

		if (make == ImagePropTextLine::className)
		{
			rc =  new ImagePropTextLine(ImageDataset::MakeWellFormedAttributeName(attribName), xmlValue);
			rc->SetOwnerType(pOwnerType);
		}

		if (make == ImagePropTextLines::className)
		{
			rc =  new ImagePropTextLines(ImageDataset::MakeWellFormedAttributeName(attribName), xmlValue);
			rc->SetOwnerType(pOwnerType);
		}
	}
	return rc;
}



//-------------------------------------------------------------------------------------------------
//			E N D   O F   F I L E
//-------------------------------------------------------------------------------------------------

